0

Php conditional Statement.

On this php educational we understand about , conditional statement.

And what is Conditional Statement?

And how Conditional Statement executes?
Maximum scripts examine situations and alternate their behavior for that reason.
This facility to make decisions makes your personal home page pages dynamic,able to changing their output in step with instances commonplace with most programming languages,php allows you to try this with an conditional declaration.

In Php We have four Conditional statement.

  1. if statement  
  2. if....else statement
  3. if....elseif.....else statement
  4. switch statement

if statement

How if statement work ?And if statement executes hear's the flow chart

if-statementflowchart
 

How if-statement work?

Run code online click here


Now we practice some simple if condition.
When you Run code online(click here) Or you localhost Out put is (Hi every one.)

Because $x=10; and if condition is $x>8; So our condition is true and output is show Hi every one.

Another example is:


Their is no out put because the value of
$x is 7 ,but condition is ($x >8) it is false.
Run code online click here

This is another if statement flow chart

This is example for practice.

Run code online click here

Another example :

Run code online click here

Explain:

$button is a variable we assigned value is "pressed".
and in the if condition if($button=="pressed") (Here ==)check $button value and type .So variable $button is equal to pressed '
In curly brackets we called echo "I am alive";
Run this code online click here

This is another example:

Output is :a is greater than b & c.

In this statement we use multiple if statement . If The first condition is true than if execute second condition.Than we see the out put .

Run this code online click here

This is another way of writing of php-If statement.
You can try this
Hope you enjoy it.In next week we discussion about if---else statement.

Post a Comment

 
check pagerank
Top